<template>
  <div>
    <!--    <button>Dealinformation</button>-->

    <!--    {"pageNum":1,"pageSize":6,"queryCondition":{"dealTimeStart":null,"dealTimeEnd":"2021-3-4","dealerCode":""}}-->
    <el-form
      ref="searchForm"
      class="searchForm"
      :model="searchForm"
      label-width="auto"
    >
      <el-row :gutter="12">
        <!--        合计24份  -->
        <el-col :span="1" :offset="3">
          <el-time-picker prop="queryCondition.dealTimeStart" label="起始时间">
            <el-input v-model.trim="searchForm.queryCondition.dealTimeStart">
            </el-input>
          </el-time-picker>
        </el-col>
        <el-col :span="6" :offset="10">
          <el-time-picker prop="queryCondition.dealTimeEnd" label="结束时间">
            <el-input v-model="searchForm.queryCondition.dealTimeEnd">
            </el-input>
          </el-time-picker>
        </el-col>
        <el-col :span="6">
          <el-form-item prop="queryCondition.dealerCode" label="交易者编号">
            <el-input v-model="searchForm.queryCondition.dealerCode">
            </el-input>
          </el-form-item>
        </el-col>
        <!--        <el-col :span="6">-->
        <!--          <el-form-item prop="queryCondition." label="最大值">-->
        <!--            <el-input v-model="searchForm.queryCondition."> </el-input>-->
        <!--          </el-form-item>-->
        <!--        </el-col>-->
      </el-row>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-edit"
          @click="queryByCondition(1)"
          >查询</el-button
        >
        <el-button
          type="warning"
          icon="el-icon-remove"
          @click="() => $refs.searchForm.resetFields()"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <!--    Response body-->
    <!--    Download-->
    <!--    {-->
    <!--    "total": 11,-->
    <!--    "results": [-->
    <!--    {-->
    <!--    "dealBillId": 25,-->
    <!--    "supplierCode": "string",-->
    <!--    "consumerCode": "",-->
    <!--    "dealTime": "2021-09-17T17:04:12",-->
    <!--    "quantity": 2,-->
    <!--    "dealState": "failed",-->
    <!--    "dealNote": "司振甫给王德功两个金币",-->
    <!--    "version": 0-->
    <!--    },-->

    <el-table :data="results" class="resultsTable" stripe height="400">
      <el-table-column prop="dealBillId" label="ID/Code" width="100px"></el-table-column>
      <!--      <el-table-column prop="dealTime" label="交易时间" width="300px" align="center"></el-table-column>-->
      <el-table-column
        prop=""
        label="交易时间"
        :formatter="DealTimeFormat"
        width="200px"
      >
      </el-table-column>
      <el-table-column prop="supplierCode" label="提供者编号"></el-table-column>
      <el-table-column prop="consumerCode" label="消费者编号"></el-table-column>
      <el-table-column prop="quantity" label="交易数量"></el-table-column>
      <el-table-column
        :formatter="dealStateFormat"
        label="交易状态"
      ></el-table-column>
      <el-table-column prop="dealNote" label="交易信息"></el-table-column>
      <el-table-column width="180px" fixed="left">
        <template slot-scope="props">
          <el-button
            class="el-button--mini"
            type="warning"
            icon="el-icon-edit"
            @click="openById(props.row.dealBillId)"
            >编辑</el-button
          >
          <el-button
            class="el-button--mini"
            type="danger"
            icon="el-icon-edit"
            @click="deleteBy(props.row.dealBill)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :total="total"
      :page-size="searchForm.pageSize"
      :current-page="searchForm.pageNum"
      @current-change="queryByCondition"
      layout="total, prev, pager, next, jumper"
    ></el-pagination>
  </div>
</template>

<script>
// import New from './components/New.vue';
export default {
  name: "Dealinformation",
  components: {
    // New,Old,
  },
  props: {
    sampleP: {
      type: Number,
      default: 0,
    },
  },
  data() {
    return {
      sampleD: "value",
      searchForm: {
        pageNum: 1,
        pageSize: 6,
        queryCondition: {
          dealTimeStart: null,
          dealTimeEnd: null,
          dealerCode: "",
        },
      },
      total: 10,
      results: [],
    };
  },
  computed: {
    // sampleC() {
    //     return this.sampleD+'--';
    dealStates() {
      return this.$store.state.dealStates;
    },
    // }
  },
  created() {},
  mounted() {
    this.queryByCondition(1);
  },
  methods: {
    sampleM() {},
    queryByCondition(pageNum) {
      if (pageNum) this.searchForm.pageNum = pageNum;
      this.$message.success(JSON.stringify(this.searchForm));
      this.$http({
        method: "post",
        url: "/ceto/dealBill/query",
        data: this.searchForm,
      }).then(
        (res) => {
          this.total = res.data.total;
          this.results = res.data.results;
        },
        (error) => {
          this.$message.warning("query mistake：" + error.response.status);
        }
      );
    },
    DealTimeFormat(row) {
      // console.log(row.dealTime);
      //2021-09-18T09:37:48
      let t = new Date(row.dealTime);
      return t.getFullYear() + "年" + t.getMonth() + "月" + t.getDate() + "日";
      //return ${}
      // return 1;
    },
    // dealStateFormat() {
    //   this.dealStates.find((x) => x.value == row.dealState);
    // },
    // index:0
    // text:"未交易"
    // value:"willing"
    dealStateFormat(row) {
      let r = this.dealStates.find((x) => x.value == row.dealState);
      return r ? r.text : "N?A";
    },
  },
  watch: {
    // sampleC(newValue, oldValue) {
    //
    // }
  },
};
</script>

<!--<style scoped>-->
<style lang="scss" scoped></style>
